<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Go语言 | anyang的博客</title>
    <meta name="description" content="千里之行,始于足下">
    <meta name="generator" content="VuePress 1.3.1">
    <link rel="icon" href="/img/favicon.ico">
  <script charset="utf-8" src="/js/main.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.slim.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.2/jquery.fancybox.min.js"></script>
  <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.2/jquery.fancybox.min.css">
  <meta name="keywords" content="福小林,奔奔,ourLang,CentOS,JAVA,vue组件,lsdCloud">
  <script async="async" src="https://www.googletagmanager.com/gtag/js?id=UA-146891701-1"></script>
  <script>window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
    
      gtag('config', 'UA-146891701-1');</script>
  <script>var _hmt = _hmt || [];
      (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?56eae8eec590ccaef1d5ff99d766f315";
        var s = document.getElementsByTagName("script")[0]; 
        s.parentNode.insertBefore(hm, s);
      })();</script>
    
    <link rel="preload" href="/assets/css/0.styles.9fff9873.css" as="style"><link rel="preload" href="/assets/js/app.1bc80adb.js" as="script"><link rel="preload" href="/assets/js/2.7c0608ab.js" as="script"><link rel="preload" href="/assets/js/63.6456dc7e.js" as="script"><link rel="prefetch" href="/assets/js/10.81caa2ab.js"><link rel="prefetch" href="/assets/js/100.05bb269d.js"><link rel="prefetch" href="/assets/js/101.3e18b4d6.js"><link rel="prefetch" href="/assets/js/102.c7d7ed9c.js"><link rel="prefetch" href="/assets/js/103.4c771ce7.js"><link rel="prefetch" href="/assets/js/104.a2acd367.js"><link rel="prefetch" href="/assets/js/105.63399350.js"><link rel="prefetch" href="/assets/js/106.8a4744cc.js"><link rel="prefetch" href="/assets/js/107.7739d796.js"><link rel="prefetch" href="/assets/js/108.8008ae33.js"><link rel="prefetch" href="/assets/js/109.01c63898.js"><link rel="prefetch" href="/assets/js/11.7b837560.js"><link rel="prefetch" href="/assets/js/110.ad01aca9.js"><link rel="prefetch" href="/assets/js/111.3d74db70.js"><link rel="prefetch" href="/assets/js/112.67f55c34.js"><link rel="prefetch" href="/assets/js/113.016cd3c0.js"><link rel="prefetch" href="/assets/js/114.860e4b2b.js"><link rel="prefetch" href="/assets/js/115.b2f26258.js"><link rel="prefetch" href="/assets/js/116.8bea67b4.js"><link rel="prefetch" href="/assets/js/117.20682843.js"><link rel="prefetch" href="/assets/js/118.86a22e16.js"><link rel="prefetch" href="/assets/js/119.ad518bea.js"><link rel="prefetch" href="/assets/js/12.8fd78714.js"><link rel="prefetch" href="/assets/js/120.f97dd86f.js"><link rel="prefetch" href="/assets/js/121.c5601b4a.js"><link rel="prefetch" href="/assets/js/122.2889645a.js"><link rel="prefetch" href="/assets/js/13.ebf26820.js"><link rel="prefetch" href="/assets/js/14.b92dca09.js"><link rel="prefetch" href="/assets/js/15.b3dcef45.js"><link rel="prefetch" href="/assets/js/16.50378990.js"><link rel="prefetch" href="/assets/js/17.056bba2b.js"><link rel="prefetch" href="/assets/js/18.9047bb38.js"><link rel="prefetch" href="/assets/js/19.ab53b0fe.js"><link rel="prefetch" href="/assets/js/20.fe0b8af0.js"><link rel="prefetch" href="/assets/js/21.20a702f3.js"><link rel="prefetch" href="/assets/js/22.0ee08d29.js"><link rel="prefetch" href="/assets/js/23.02039a9a.js"><link rel="prefetch" href="/assets/js/24.363d3d74.js"><link rel="prefetch" href="/assets/js/25.dd6b101e.js"><link rel="prefetch" href="/assets/js/26.20493714.js"><link rel="prefetch" href="/assets/js/27.708723e5.js"><link rel="prefetch" href="/assets/js/28.4561834a.js"><link rel="prefetch" href="/assets/js/29.15cfcf5f.js"><link rel="prefetch" href="/assets/js/3.8d39d40c.js"><link rel="prefetch" href="/assets/js/30.04ab69de.js"><link rel="prefetch" href="/assets/js/31.b11c4302.js"><link rel="prefetch" href="/assets/js/32.81ae74ee.js"><link rel="prefetch" href="/assets/js/33.ddf09cc0.js"><link rel="prefetch" href="/assets/js/34.bc3549f7.js"><link rel="prefetch" href="/assets/js/35.4a0e0ebd.js"><link rel="prefetch" href="/assets/js/36.961a1c50.js"><link rel="prefetch" href="/assets/js/37.d8658de5.js"><link rel="prefetch" href="/assets/js/38.f76063aa.js"><link rel="prefetch" href="/assets/js/39.73edd08f.js"><link rel="prefetch" href="/assets/js/4.916af9bf.js"><link rel="prefetch" href="/assets/js/40.72314bff.js"><link rel="prefetch" href="/assets/js/41.c5eb1147.js"><link rel="prefetch" href="/assets/js/42.07aeafbb.js"><link rel="prefetch" href="/assets/js/43.c4a652ba.js"><link rel="prefetch" href="/assets/js/44.91fbe22b.js"><link rel="prefetch" href="/assets/js/45.6eecf0c4.js"><link rel="prefetch" href="/assets/js/46.81b7f108.js"><link rel="prefetch" href="/assets/js/47.b4468ab3.js"><link rel="prefetch" href="/assets/js/48.df205f23.js"><link rel="prefetch" href="/assets/js/49.7df59fa3.js"><link rel="prefetch" href="/assets/js/5.4fcd540a.js"><link rel="prefetch" href="/assets/js/50.0dc2fc5b.js"><link rel="prefetch" href="/assets/js/51.1ffabe54.js"><link rel="prefetch" href="/assets/js/52.2269d284.js"><link rel="prefetch" href="/assets/js/53.81b23843.js"><link rel="prefetch" href="/assets/js/54.b3249def.js"><link rel="prefetch" href="/assets/js/55.50dcf2af.js"><link rel="prefetch" href="/assets/js/56.c399c272.js"><link rel="prefetch" href="/assets/js/57.024f1dbb.js"><link rel="prefetch" href="/assets/js/58.680c6cf4.js"><link rel="prefetch" href="/assets/js/59.2291e9d7.js"><link rel="prefetch" href="/assets/js/6.7610d1d4.js"><link rel="prefetch" href="/assets/js/60.e59a26c1.js"><link rel="prefetch" href="/assets/js/61.ff5c64e4.js"><link rel="prefetch" href="/assets/js/62.7d97062c.js"><link rel="prefetch" href="/assets/js/64.0b055680.js"><link rel="prefetch" href="/assets/js/65.9f25601c.js"><link rel="prefetch" href="/assets/js/66.cd973084.js"><link rel="prefetch" href="/assets/js/67.9b8f9716.js"><link rel="prefetch" href="/assets/js/68.d6c1869a.js"><link rel="prefetch" href="/assets/js/69.0a3688dd.js"><link rel="prefetch" href="/assets/js/7.9ebbd956.js"><link rel="prefetch" href="/assets/js/70.22f48891.js"><link rel="prefetch" href="/assets/js/71.9eb4fda9.js"><link rel="prefetch" href="/assets/js/72.ca4fa80c.js"><link rel="prefetch" href="/assets/js/73.17d1ab37.js"><link rel="prefetch" href="/assets/js/74.139691db.js"><link rel="prefetch" href="/assets/js/75.08d0560f.js"><link rel="prefetch" href="/assets/js/76.61078c10.js"><link rel="prefetch" href="/assets/js/77.4482adcc.js"><link rel="prefetch" href="/assets/js/78.166f2c37.js"><link rel="prefetch" href="/assets/js/79.2c7d6b79.js"><link rel="prefetch" href="/assets/js/8.6f8916c2.js"><link rel="prefetch" href="/assets/js/80.80445c3f.js"><link rel="prefetch" href="/assets/js/81.14e3bae8.js"><link rel="prefetch" href="/assets/js/82.7dac687f.js"><link rel="prefetch" href="/assets/js/83.1dd2e78e.js"><link rel="prefetch" href="/assets/js/84.23b759de.js"><link rel="prefetch" href="/assets/js/85.7574f69f.js"><link rel="prefetch" href="/assets/js/86.102dac61.js"><link rel="prefetch" href="/assets/js/87.8f5d639e.js"><link rel="prefetch" href="/assets/js/88.e564cbbe.js"><link rel="prefetch" href="/assets/js/89.cd66eb78.js"><link rel="prefetch" href="/assets/js/9.baa162db.js"><link rel="prefetch" href="/assets/js/90.685c6878.js"><link rel="prefetch" href="/assets/js/91.b8d1b7ea.js"><link rel="prefetch" href="/assets/js/92.1faa374d.js"><link rel="prefetch" href="/assets/js/93.cf5ff33c.js"><link rel="prefetch" href="/assets/js/94.8a02aefb.js"><link rel="prefetch" href="/assets/js/95.1b379a5b.js"><link rel="prefetch" href="/assets/js/96.9fd67185.js"><link rel="prefetch" href="/assets/js/97.c5a6a5a1.js"><link rel="prefetch" href="/assets/js/98.9a231411.js"><link rel="prefetch" href="/assets/js/99.5b344cab.js">
    <link rel="stylesheet" href="/assets/css/0.styles.9fff9873.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">anyang的博客</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">
  主页
</a></div><div class="nav-item"><a href="/study-guide/introduction.html" class="nav-link">
  学习指南
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="技术分类" class="dropdown-title"><span class="title">技术分类</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/java/introduction.html" class="nav-link">
  Java
</a></li><li class="dropdown-item"><!----> <a href="/go/introduction.html" class="nav-link router-link-exact-active router-link-active">
  Go
</a></li><li class="dropdown-item"><!----> <a href="/sql/introduction.html" class="nav-link">
  SQL
</a></li><li class="dropdown-item"><!----> <a href="/fhir/introduction.html" class="nav-link">
  FHIR
</a></li></ul></div></div><div class="nav-item"><a href="/blog/introduction.html" class="nav-link">
  个人博客
</a></div><div class="nav-item"><a href="/tool/developmentBox.html" class="nav-link">
  开发百宝箱
</a></div><div class="nav-item"><a href="/project/introduction.html" class="nav-link">
  项目分享
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="了解更多" class="dropdown-title"><span class="title">了解更多</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="http://wpa.qq.com/msgrd?v=3&amp;uin=1300378587&amp;site=qq&amp;menu=yes" target="_blank" rel="noopener noreferrer" class="nav-link external">
  其他合作
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="http://www.lsdcloud.com/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  友情网站
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://github.com/ourlang" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Github
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://gitee.com/anlexanyang" target="_blank" rel="noopener noreferrer" class="nav-link external">
  码云
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://blog.csdn.net/qq_37493556" target="_blank" rel="noopener noreferrer" class="nav-link external">
  CSDN
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div></div><div class="nav-item"><a href="/linkExchanges/introduction.html" class="nav-link">
  友情链接
</a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">
  主页
</a></div><div class="nav-item"><a href="/study-guide/introduction.html" class="nav-link">
  学习指南
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="技术分类" class="dropdown-title"><span class="title">技术分类</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/java/introduction.html" class="nav-link">
  Java
</a></li><li class="dropdown-item"><!----> <a href="/go/introduction.html" class="nav-link router-link-exact-active router-link-active">
  Go
</a></li><li class="dropdown-item"><!----> <a href="/sql/introduction.html" class="nav-link">
  SQL
</a></li><li class="dropdown-item"><!----> <a href="/fhir/introduction.html" class="nav-link">
  FHIR
</a></li></ul></div></div><div class="nav-item"><a href="/blog/introduction.html" class="nav-link">
  个人博客
</a></div><div class="nav-item"><a href="/tool/developmentBox.html" class="nav-link">
  开发百宝箱
</a></div><div class="nav-item"><a href="/project/introduction.html" class="nav-link">
  项目分享
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="了解更多" class="dropdown-title"><span class="title">了解更多</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="http://wpa.qq.com/msgrd?v=3&amp;uin=1300378587&amp;site=qq&amp;menu=yes" target="_blank" rel="noopener noreferrer" class="nav-link external">
  其他合作
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="http://www.lsdcloud.com/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  友情网站
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://github.com/ourlang" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Github
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://gitee.com/anlexanyang" target="_blank" rel="noopener noreferrer" class="nav-link external">
  码云
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://blog.csdn.net/qq_37493556" target="_blank" rel="noopener noreferrer" class="nav-link external">
  CSDN
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div></div><div class="nav-item"><a href="/linkExchanges/introduction.html" class="nav-link">
  友情链接
</a></div> <!----></nav>  <ul class="sidebar-links"><li><a href="/go/introduction.html" class="active sidebar-link">Go语言</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/go/introduction.html#_1-什么是go语言？" class="sidebar-link">1 什么是Go语言？</a></li><li class="sidebar-sub-header"><a href="/go/introduction.html#_2-go语言特性" class="sidebar-link">2 Go语言特性</a></li><li class="sidebar-sub-header"><a href="/go/introduction.html#_3-go语言适合做什么" class="sidebar-link">3 Go语言适合做什么</a></li><li class="sidebar-sub-header"><a href="/go/introduction.html#_4-go语言和其它编程语言的对比" class="sidebar-link">4 Go语言和其它编程语言的对比</a></li></ul></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Go教程</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Go Web框架</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Go工具中间件</span> <span class="arrow right"></span></p> <!----></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="go语言"><a href="#go语言" class="header-anchor">#</a> Go语言</h1> <p><img src="/img/goImage/golang.jpg" alt="golang"></p> <h2 id="_1-什么是go语言？"><a href="#_1-什么是go语言？" class="header-anchor">#</a> 1 什么是Go语言？</h2> <p>Go语言也称 Golang，兼具效率、性能、安全、健壮等特性。Go语言从底层原生支持并发，无须第三方库、开发者的编程技巧和开发经验就可以轻松搞定
写代码更加高效；优化了多处理器系统的应用程序，使其可以媲美C或者C++代码程序的速度。另外，他更加安全的支持并行进程；</p> <p>Go语言不仅提供了高性能语言，同时让开发更加迅速；</p> <p>Go语言是一门编译型的系统编程语言，具有静态编译语言的高性能和动态语言的高效开发双重特点。</p> <h2 id="_2-go语言特性"><a href="#_2-go语言特性" class="header-anchor">#</a> 2 Go语言特性</h2> <h4 id="_2-1-自动垃圾回收"><a href="#_2-1-自动垃圾回收" class="header-anchor">#</a> 2.1 自动垃圾回收</h4> <p>在Go语言中，系统会自动判断何时需要释放之前分配的内存空间，并在CPU相对空闲时对不使用的内存进行收集。</p> <h4 id="_2-2-丰富的内置类型"><a href="#_2-2-丰富的内置类型" class="header-anchor">#</a> 2.2 丰富的内置类型</h4> <p>在Go语言中，内置类型包含：整型，浮点型，数组，字符串，字典map，切片slice。因为语言的内置特性，开发者不用添加依赖的包，让代码更简洁。</p> <h4 id="_2-3-函数多返回值"><a href="#_2-3-函数多返回值" class="header-anchor">#</a> 2.3 函数多返回值</h4> <p>Go语言是静态开发语言中率先提供多返回值功能的语言。如果开发者只关心函数中的某几个返回值，可以直接使用下划线作为占位符忽略其他不关心的返回值。</p> <h4 id="_2-4-异常处理"><a href="#_2-4-异常处理" class="header-anchor">#</a> 2.4 异常处理</h4> <p>异常处理涉及3个关键字：error、panic和recover。其中error报告程序中的普通错误，panic报告程序中的致命性错误，而recover可以让程序从panic状态中恢复。</p> <h4 id="_2-5-匿名函数与闭包"><a href="#_2-5-匿名函数与闭包" class="header-anchor">#</a> 2.5 匿名函数与闭包</h4> <p>匿名函数就是没有定义函数名的一种函数。而在Go语言中，闭包就是匿名函数，它可以通过匿名函数“捕获”和它在同一作用域的其它常量和变量。</p> <h4 id="_2-6-结构体"><a href="#_2-6-结构体" class="header-anchor">#</a> 2.6 结构体</h4> <p>结构体是一系列具有相同或不同类型的数据构成的数据集合。例如，可以利用结构体定义一个学生的学号/姓名/性别/年龄等属性。</p> <h4 id="_2-7-接口"><a href="#_2-7-接口" class="header-anchor">#</a> 2.7 接口</h4> <p>接口是具体描述一系列方法的集合。例如，可以利用接口将一个人的说、唱这些行为集中到一起。</p> <h4 id="_2-8-并发编程"><a href="#_2-8-并发编程" class="header-anchor">#</a> 2.8 并发编程</h4> <p>并发编程，就是在同一时刻只能有一条指令执行，但多个进程指令被快速的轮换执行，使得在宏观上具有多个进程同时执行的效果，但在微观上并不是同时执行的，只是把时间分成若干段，使多个进程快速交替的执行。如图所示。</p> <p>Golang从语言级别上对并发提供了支持，goroutine是Go并发设计的核心，而goroutine就是Go语言实现的协程。在Go程序里，只需要在函数调⽤语句前添加关键字“go”，就可创建并发执行单元。</p> <h2 id="_3-go语言适合做什么"><a href="#_3-go语言适合做什么" class="header-anchor">#</a> 3 Go语言适合做什么</h2> <p>其实Go语言主要用作服务器端开发，其定位是用来开发“大型软件”的，适合于需要很多程序员一起开发，并且开发周期较长的大型软件和支持云计算的网络服务。</p> <p>Go语言融合了传统编译型语言的高效性和脚本语言的易用性和富于表达性，不仅提高了项目的开发速度，而且后期维护起来也非常轻松。</p> <p>鉴于Go语言的特点和设计的初衷，从以下几个方面来分析Go语言擅长的领域：
在服务器编程方面，Go语言适合处理日志、数据打包、虚拟机处理、文件系统、分布式系统、数据库代理等；
网络编程方面，Go语言广泛应用于 Web 应用、API 应用、下载应用等；
此外，Go语言还可用于内存数据库和云平台领域，目前国外很多云平台都是采用 Go 开发。</p> <p>除了上面介绍到的，Go语言还可以用来开发底层，例如以太坊、超级账本等都是基于Go语言开发的。</p> <p>而且对于现在比较流行的区块链技术方面，Go语言也是非常受欢迎的，很多基于区块链的 DApps（去中心化应用）和工具都是用的Go语言来实现的。</p> <p>下面列举了一些基于Go语言开发的优秀开源项目：</p> <ul><li>云计算基础设施领域,代表项目:docker、kubernetes、etcd、consul、cloudflare CDN、七牛云存储等。</li> <li>基础软件，代表项目：tidb、influxdb、cockroachdb 等。</li> <li>微服务，代表项目：go-kit、micro、monzo bank 的 typhon、bilibili 等。</li> <li>互联网基础设施，代表项目：以太坊、hyperledger 等。</li></ul> <p>总之，Go语言的优势还是比较多的，比如Go语言的性能非常出色，最关键的是在性能强劲的同时还能像解释型语言一样高效地进行开发。</p> <h2 id="_4-go语言和其它编程语言的对比"><a href="#_4-go语言和其它编程语言的对比" class="header-anchor">#</a> 4 Go语言和其它编程语言的对比</h2> <p>在软件行业做过一段时间的人都知道，没有万能的编程语言，也没有万能开发框架，更没有万能的解决方案。任何新技术的产生都应该归功于一部分人对老旧技术的强烈不满。Go语言也不例外。比如，C语言的依赖管理、C++ 的垃圾回收、Java 笨重的类型系统和厚重的 Java EE 规范，以及脚本语言（如 PHP、Python 和 Ruby）的性能，这些都是很多开发者社区经常争论和抱怨的问题。
Go语言的优势
Go语言是集多编程范式之大成者，体现了优秀的软件工程思想和原则，其特性可以使开发者快速地开发、测试和部署程序，大大提高了生产效率。下面我们来看看与其他主流语言相比，Go语言具有的优势。</p> <ol><li><p>相对于 C/C++ 来讲，Go语言拥有清晰的依赖管理和全自动的垃圾回收机制，因此其代码量大大降低，开发效率大大提高。</p></li> <li><p>相对于 Java 来讲，Go语言拥有简明的类型系统、函数式编程范式和先进的并发编程模型。因此其代码块更小更简洁、可重用性更高，并可在多核计算环境下更快地运行。</p></li> <li><p>对于 PHP 来讲，Go语言更具通用性和规范性。这使得其更适合构建大型的软件，并能够更好地将各个模块组织在一起。在性能方面，PHP 不可与 Go 同日而语。</p></li> <li><p>对于 Python/Ruby 来讲，Go 的优势在于其简洁的语法、非侵入式和扁平化的类型系统和浑然天成的多范式编程模型。与 PHP 一样，Python 和 Ruby 也是动态类型的解释型语言，这就意味着它们的运行速度会比静态类型的编译型语言慢很多。</p></li></ol> <p>总而言之，Go语言对于当前大多数主流语言来讲，最大的优势在于具有较高的生产效率、先进的依赖管理和类型系统，以及原生的并发计算支持。因此，Go语言自发布以来就受到了各个领域开发者的关注和青睐。
Go语言的劣势
下面，我们来客观地看一下目前Go语言需要加强或改进的地方（虽然有些 Gopher 并不这么认为）。</p> <ol><li><p>从分布式计算的角度来看，Go语言的成熟度不及 Erlang（现在已经出现了一些这方面的Go语言代码包，我们已经可以看到光明的未来了）。</p></li> <li><p>从程序运行速度的角度来看，Go语言虽然已与 Java 不相上下，但还不及 C（差距正在不断地缩小）。</p></li> <li><p>从第三方库的角度来看，Go语言的库数量还远远不及其他几门主流语言（比如 Java、Python、Ruby 等）。不过与Go语言的年纪相比，用它实现的第三方库已经相当多了，并且它们的数量在持续地飞速增长中。</p></li></ol> <p>另外，在更深的层面，Go语言标准库中也有些不尽如人意的的地方。具体如下。</p> <ol><li><p>从语言语法角度来看，Go语言语法里的语法糖并不多，这让许多 Python、Ruby 爱好者们对它不屑一顾。另外，变量赋值方式多得有点儿累赘了。最让人遗憾的也是我比较在意的一个地方是，Go语言不支持自定义的泛型类型。</p></li> <li><p>从并发编程角度来看，Go语言提供的并发模型很强大，但也有一些编写规则需要了解。否则，很容易踩进“坑”里。其实不提倡把这叫作“坑”。因为这些所谓的“坑”，大都是我们由于对原理不熟悉而自己挖出来的。</p></li> <li><p>从垃圾回收角度看，Go语言的垃圾回收采用的是并发的标记清除算法（Concurrent Mark and Sweep，CMS）。虽然是并发的操作，时间比串行操作短很多，但是还是会在垃圾回收期间停止所有用户程序的操作。这一点多少会影响到对实时性要求比较高的应用。不过，在Go语言 1.3 之后的版本中，这方面的问题已经得到了极大的改善。</p></li></ol> <p>虽然Go语言还有一些瑕疵，但从整体来看，它已经是一门非常优秀的通用编程语言了。并且，Go语言在今后的发展上会关注性能、可靠性、可移植性和一些功能增强，所以上述缺憾会随着版本的推进而逐渐减弱和消失。</p></div> <footer class="page-edit"><!----> <!----></footer> <div class="page-nav"><p class="inner"><!----> <span class="next"><a href="/go/learn-go/10 从零搭建Go语言开发环境.html">
        从零搭建Go语言开发环境
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"><!----></div></div>
    <script src="/assets/js/app.1bc80adb.js" defer></script><script src="/assets/js/2.7c0608ab.js" defer></script><script src="/assets/js/63.6456dc7e.js" defer></script>
  </body>
</html>
